package com.my.hp_hr.contorller;

import com.my.hp_hr.entity.Department;
import com.my.hp_hr.entity.History;
import com.my.hp_hr.entity.Position;
import com.my.hp_hr.service.HistoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/preHistoryAddServlet")
public class PreEmployeeAddServlet extends HttpServlet {
    private HistoryService historyService = new HistoryService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            List<Position> position = historyService.getPosition();
            List<Department> department = historyService.getDepartment();
            req.setAttribute("position",position);
            req.setAttribute("department",department);
            int employee_number = historyService.getAllHistory();
            //System.out.println(employee_number);
            req.setAttribute("employee_number",employee_number);
            req.getRequestDispatcher("employee_add.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
